/* drivers/video/sprdfb/lcd/lcd_ft8006m_mipi.c
 *
 * Support for ft8006m mipi LCD device
 *
 * Copyright (C) 2010 Spreadtrum
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "../sprdfb_chip_common.h"
#include "../sprdfb.h"
#include "../sprdfb_panel.h"

//#define LCD_Delay(ms)  uDelay(ms*1000)
///#define printk printf

#define  LCD_DEBUG
#ifdef LCD_DEBUG
#define LCD_PRINT printk
#else
#define LCD_PRINT(...)
#endif

#define MAX_DATA   56

typedef struct LCM_Init_Code_tag {
	unsigned int tag;
	unsigned char data[MAX_DATA];
}LCM_Init_Code;

typedef struct LCM_force_cmd_code_tag{
	unsigned int datatype;
	LCM_Init_Code real_cmd_code;
}LCM_Force_Cmd_Code;

#define LCM_TAG_SHIFT 24
#define LCM_TAG_MASK  ((1 << 24) -1)
#define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)
#define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)
//#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))

#define LCM_TAG_SEND  (1<< 0)
#define LCM_TAG_SLEEP (1 << 1)

static LCM_Init_Code init_data[] = {
#if 1   //L513 HAIFEI
{LCM_SEND(5),{3,0,0x50,0x5A,0x08}},
{LCM_SEND(5),{3,0,0x80,0xC8,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x09}},
{LCM_SEND(19),{17,0,0x80,0x5A,0x51,0xB5,0x2A,0x6C,0xA5,0x4A,0x01,0x40,0xE0,0x0D,0x82,0x20,0x08,0x30,0x4B}},
{LCM_SEND(19),{17,0,0x90,0x00,0x00,0x42,0x0A,0xE3,0x25,0x9B,0x70,0xA5,0xB5,0x67,0x20,0x41,0xA1,0x26,0x00}},
{LCM_SEND(9),{7,0,0xA0,0xA1,0x80,0x08,0x20,0x06,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x0A}},
{LCM_SEND(19),{17,0,0x80,0x51,0xA3,0x02,0x00,0x18,0x2E,0x3F,0x56,0x69,0x6E,0xA0,0x8B,0xBE,0x7F,0x51,0x85}},
{LCM_SEND(19),{17,0,0x90,0x59,0x55,0x44,0x33,0x1E,0x16,0x0F,0x00,0x18,0x2E,0x3F,0x56,0x69,0x6E,0xA0,0x8B}},
{LCM_SEND(19),{17,0,0xA0,0xBE,0x7F,0x51,0x85,0x59,0x55,0x44,0x33,0x1E,0x16,0x0F,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x0B}},
{LCM_SEND(19),{17,0,0x80,0x00,0x00,0x20,0x44,0x08,0x00,0x60,0x47,0x00,0x00,0x10,0x22,0x04,0x00,0xB0,0x23}},
{LCM_SEND(5),{3,0,0x90,0x15,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x0C}},
{LCM_SEND(19),{17,0,0x80,0xFA,0x68,0x68,0x01,0x28,0x69,0x00,0x04,0x00,0x60,0x15,0x00,0x50,0x15,0x56,0x51}},
{LCM_SEND(19),{17,0,0x90,0x15,0x55,0x61,0x15,0x00,0x60,0x15,0x00,0x50,0x15,0x56,0x51,0x15,0x55,0x61,0x95}},
{LCM_SEND(19),{17,0,0xA0,0xAB,0x18,0x00,0x05,0x00,0x05,0x00,0x05,0x80,0x4C,0x29,0x84,0x52,0x01,0x09,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x0D}},
{LCM_SEND(17),{15,0,0x80,0xF0,0xB1,0x71,0xEF,0x49,0xC0,0x80,0x1A,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x0E}},
{LCM_SEND(15),{13,0,0x80,0xFF,0x81,0x68,0x6C,0x22,0x6D,0x24,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x0F}},
{LCM_SEND(19),{17,0,0x80,0x97,0xC4,0x58,0x00,0x19,0x60,0x64,0x10,0x53,0x33,0xC8,0x50,0x01,0x82,0x8C,0x8C}},
{LCM_SEND(10),{8,0,0x90,0x24,0x69,0x81,0x71,0x44,0x7C,0x14}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x10}},
{LCM_SEND(19),{17,0,0x80,0x00,0x80,0x03,0xE7,0x1F,0x17,0x20,0x48,0x00,0x52,0xCD,0x18,0x30,0x88,0x41,0x8A}},
{LCM_SEND(18),{16,0,0x90,0x39,0x28,0xA9,0xC5,0x9A,0x7B,0xF0,0x07,0x7E,0xE0,0x07,0x7E,0x20,0x10,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x11}},
{LCM_SEND(19),{17,0,0x80,0x46,0x77,0x03,0x40,0xCA,0xF3,0xFF,0x83,0x30,0x08,0xC4,0x06,0xA1,0xD8,0x24,0x18}},
{LCM_SEND(19),{17,0,0x90,0x30,0xC6,0x66,0xC1,0x80,0x31,0x15,0xCB,0xE5,0xD2,0x68,0x6C,0x36,0x1D,0x04,0xC8}},
{LCM_SEND(19),{17,0,0xA0,0xB0,0xD9,0x88,0x60,0xB0,0x81,0x40,0x1A,0x1B,0x48,0x63,0x03,0xB9,0x00,0x1C,0x80}},
{LCM_SEND(19),{17,0,0xB0,0x50,0x30,0x00,0xE0,0xE1,0x01,0x00,0x28,0x0E,0x06,0x43,0x55,0x55,0x55,0x55,0x55}},
{LCM_SEND(19),{17,0,0xC0,0x95,0x88,0x88,0x88,0x88,0x88,0xC8,0x08,0x86,0xC6,0xE3,0x81,0x00,0x20,0x00,0x21}},
{LCM_SEND(19),{17,0,0xD0,0x42,0x88,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x31,0x04,0x41,0x06,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0xE0,0x00,0x92,0x24,0x49,0x92,0x04,0x00,0x00,0x00,0x00,0x92,0x04,0x00,0x85,0x11,0x0C}},
{LCM_SEND(12),{10,0,0xF0,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x5E,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x12}},
{LCM_SEND(19),{17,0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(12),{10,0,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x13}},
{LCM_SEND(19),{17,0,0x80,0x01,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x1C,0x44,0x0C,0xCE,0xE7}},
{LCM_SEND(6),{4,0,0x90,0x62,0x0E,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x14}},
{LCM_SEND(19),{17,0,0x80,0x51,0x01,0x40,0x5E,0xE9,0xEF,0xF7,0xFB,0xFD,0x7E,0x01,0x00,0x00,0x40,0xC5,0x05}},
{LCM_SEND(19),{17,0,0x90,0x6A,0x3E,0x60,0x03,0xD4,0x33,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0xFC,0xA8,0x83,0x1A,0x00,0x40,0xA1}},
{LCM_SEND(19),{17,0,0xC0,0x50,0x78,0x07,0xA8,0xF9,0x80,0x73,0x00,0x2F,0x00,0x35,0x1F,0x70,0x0E,0xE0,0x25}},
{LCM_SEND(19),{17,0,0xD0,0xA0,0xE6,0x03,0xCE,0x01,0xBC,0x08,0xD4,0x7C,0xC0,0x39,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x15}},
{LCM_SEND(19),{17,0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0x90,0x00,0x00,0x81,0x62,0xC4,0xA8,0xD5,0x86,0xD0,0x6A,0x1D,0x31,0x6A,0xB5,0x21,0xB4}},
{LCM_SEND(19),{17,0,0xA0,0x5A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(19),{17,0,0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0xF0,0x00,0x94,0xA9,0x55,0xD7}},
{LCM_SEND(19),{17,0,0xC0,0xB5,0x6D,0xDB,0xF6,0x28,0xDA,0x76,0x08,0xA2,0xB6,0x6D,0xDB,0xB6,0x85,0xDA,0x55}},
{LCM_SEND(19),{17,0,0xD0,0x5D,0xDB,0xB6,0x6D,0x01,0xA1,0x6D,0x09,0x43,0x6A,0xDB,0xB6,0x6D,0x5B,0xA9,0x55}},
{LCM_SEND(19),{17,0,0xE0,0xD7,0xB5,0x6D,0xDB,0xD6,0x20,0xDA,0x56,0x00,0xA0,0xB6,0x6D,0xDB,0xB6,0x8D,0xDA}},
{LCM_SEND(19),{17,0,0xF0,0x55,0x5D,0xDB,0xB6,0x6D,0x83,0xA1,0x6D,0x8B,0x63,0x6A,0xDB,0xB6,0x6D,0x5B,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x16}},
{LCM_SEND(19),{17,0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(9),{7,0,0x90,0x00,0x00,0x00,0x00,0xD0,0x40}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x18}},
{LCM_SEND(19),{17,0,0x80,0xEF,0xBD,0xF7,0xDE,0x7B,0xEF,0xBD,0x07,0x08,0x08,0x0A,0x0C,0x0C,0x0C,0x0C,0x0C}},
{LCM_SEND(19),{17,0,0x90,0x0C,0x0C,0x0C,0x5C,0x09,0xA8,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x5A}},
{LCM_SEND(19),{17,0,0xA0,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x09,0x04,0xFF,0x05,0x80}},
{LCM_SEND(18),{16,0,0xB0,0x80,0x00,0x04,0x20,0x00,0x01,0x08,0x40,0x00,0x02,0x10,0x80,0x00,0x04,0x0F}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x19}},
{LCM_SEND(19),{17,0,0x80,0xF0,0xD9,0xC8,0xBA,0xAF,0xA6,0x9E,0x98,0x92,0x8D,0x88,0x84,0x00,0xF0,0x6F,0xF6}},
{LCM_SEND(19),{17,0,0x90,0xCF,0xFC,0x6F,0xF6,0xFE,0xFC,0x0A,0xFF,0xAF,0xB5,0x71,0x0E,0x6C,0x4A,0x69,0x08}},
{LCM_SEND(10),{8,0,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x1B}},
{LCM_SEND(19),{17,0,0x80,0xA0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC}},
{LCM_SEND(7),{5,0,0x90,0xFE,0xFF,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x20}},
{LCM_SEND(10),{8,0,0x80,0x8C,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x22}},
{LCM_SEND(16),{14,0,0x80,0xAD,0xD4,0x00,0x41,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x1F,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x23}},
{LCM_SEND(19),{17,0,0x80,0x01,0x05,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(12),{10,0,0x90,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x24}},
{LCM_SEND(19),{17,0,0x80,0x00,0x03,0x00,0x9D,0xBF,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF1,0x1C}},
{LCM_SEND(2),{0x90,0x5A}},
{LCM_SEND(2),{0x90,0xA5}},
{LCM_SEND(5),{3,0,0x50,0x5A,0x2F}},
{LCM_SEND(2),{0x09,0x01}},
//#----------------------------TP€p§| 0x00=Enable¡F0x01=Disable
{LCM_SEND(5),{3,0,0x50,0x5A,0x0A}},

//#Gamma+
{LCM_SEND(23),{21,0,0x83,0x00,0x25,0x39,0x50,0x64,0x77,0x7d,0xad,0xa2,0xd1,0x6e,0x42,0x80,0x58,0x55,0x45,0x35,0x22,0x0d,0x00}},
//#Gamma-
{LCM_SEND(23),{21,0,0x97,0x00,0x25,0x39,0x50,0x64,0x77,0x7d,0xad,0xa2,0xd1,0x6e,0x42,0x80,0x58,0x55,0x45,0x35,0x22,0x0d,0x00}},
{LCM_SEND(2),{0xAB,0x00}},

{LCM_SEND(2),{0x11,0x00}},
{LCM_SLEEP(120)},
// Display ON
{LCM_SEND(2),{0x29,0x00}},
{LCM_SLEEP(10)},

#endif
#if 0
//Stop reload
        {LCM_SEND(2),{0x50,0x5A}},

//INT CANCEL
        {LCM_SEND(2),{0x54,0x03}},

//VCOM
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x03}},
        {LCM_SEND(5),{3, 0, 0x80,0x30,0x01}},

//Blank 8
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x08}},
        {LCM_SEND(5),{3, 0, 0x80,0xC8,0x00}},
//Blank 9
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x09}},
        {LCM_SEND(19),{17, 0, 0x80,0x5A,0x51,0xB5,0x2A,0x6C,0xC5,0x4A,0x01,0x60,0xE1,0x0F,0xC1,0x10,0x0C,0x30,0x4B}},
        {LCM_SEND(19),{17, 0, 0x90,0x00,0x00,0x42,0x0A,0xE3,0x29,0x9B,0xF0,0xB9,0xE1,0x6B,0x68,0x5F,0x81,0x26,0x00}},
        {LCM_SEND(9),{7, 0, 0xA0,0xA1,0x80,0x08,0x20,0x06,0x00}},
//Blank 10
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x0A}},
        {LCM_SEND(19),{17, 0, 0x80,0x83,0x8D,0x03,0x00,0x09,0x11,0x1D,0x2A,0x37,0x39,0x6A,0x2C,0x6C,0xC3,0x83,0x98}},
        {LCM_SEND(19),{17, 0, 0x90,0x63,0x5D,0x4B,0x39,0x27,0x15,0x06,0x00,0x09,0x11,0x1D,0x2A,0x37,0x39,0x6A,0x2C}},
        {LCM_SEND(15),{13, 0, 0xA0,0x6C,0xC3,0x83,0x98,0x63,0x5D,0x4B,0x39,0x27,0x15,0x06,0x00}},
//Blank 11
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x0B}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x00,0x20,0x44,0x08,0x00,0x60,0x47,0x00,0x00,0x10,0x22,0x04,0x00,0xB0,0x23}},
        {LCM_SEND(5),{3, 0, 0x90,0x15,0x00}},
//Blank 12
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x0C}},
        {LCM_SEND(19),{17, 0, 0x80,0xFA,0x68,0x68,0x01,0x2D,0x6E,0x10,0x08,0x00,0x60,0x15,0x00,0x50,0x15,0x56,0x51}},
        {LCM_SEND(19),{17, 0, 0x90,0x15,0x55,0x61,0x15,0x00,0x60,0x15,0x00,0x50,0x15,0x56,0x51,0x15,0x55,0x61,0x95}},
        {LCM_SEND(19),{17, 0, 0xA0,0xAB,0x18,0x00,0x05,0x00,0x05,0x00,0x05,0x80,0x4C,0x29,0x84,0x52,0x01,0x09,0x00}},
//Blank 13
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x0D}},
        {LCM_SEND(17),{15, 0, 0x80,0xF1,0xB1,0x71,0xEF,0x49,0xC0,0x80,0x1A,0x00,0x00,0x00,0x00,0x00,0x00}},
//Blank 14
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x0E}},
        {LCM_SEND(15),{13, 0, 0x80,0xFF,0x81,0x68,0xAC,0x22,0x6D,0x24,0x00,0x00,0x00,0x00,0x00}},
//Blank 15
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x0F}},
        {LCM_SEND(19),{17, 0, 0x80,0x59,0xCC,0x48,0x20,0x1C,0x58,0x64,0x10,0x53,0x33,0xE8,0x50,0x01,0x32,0x8C,0x8C}},
        {LCM_SEND(10),{8, 0, 0x90,0x24,0x69,0x81,0x71,0x44,0x7C,0x14}},
//Blank 16
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x10}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x80,0x03,0xE7,0x1F,0x17,0x00,0x48,0x40,0x02,0xCF,0x18,0x30,0x88,0x41,0x8A}},
        {LCM_SEND(18),{16, 0, 0x90,0x39,0x28,0xA9,0xC5,0x9A,0x7B,0xF0,0x07,0x7E,0xE0,0x07,0x7E,0x20,0x10,0x00}},
//Blank 17
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x11}},
        {LCM_SEND(19),{17, 0, 0x80,0x43,0x77,0x03,0x40,0x8A,0xF1,0xFF,0x43,0x30,0x08,0xC1,0x46,0xA0,0x80,0x24,0x18}},
        {LCM_SEND(19),{17, 0, 0x90,0x30,0x06,0x64,0xC1,0x80,0x11,0x07,0xC4,0xE1,0xD0,0x68,0x40,0x20,0x1D,0x04,0x48}},
        {LCM_SEND(19),{17, 0, 0xA0,0x40,0x40,0x28,0x10,0x60,0x70,0x38,0x1A,0x10,0x47,0x03,0xE2,0x20,0x00,0x1C,0x80}},
        {LCM_SEND(19),{17, 0, 0xB0,0x50,0x30,0x00,0xE0,0xE1,0x01,0x00,0x28,0x0E,0x06,0xC3,0xCC,0xCC,0xCC,0xCC,0xCC}},
        {LCM_SEND(19),{17, 0, 0xC0,0x8C,0x88,0x88,0x88,0x88,0x88,0xC8,0x08,0x86,0xC6,0xE3,0x81,0x00,0x20,0x00,0x21}},
        {LCM_SEND(19),{17, 0, 0xD0,0x42,0x88,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x31,0x04,0x41,0x06,0x00,0x00,0x00}},
        {LCM_SEND(19),{17, 0, 0xE0,0x00,0x92,0x24,0x49,0x92,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x85,0x11,0x0C}},
        {LCM_SEND(12),{10, 0, 0xF0,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x5E,0x00}},
//Blank 18
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x12}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
        {LCM_SEND(12),{10, 0, 0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
//Blank 19
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x13}},
        {LCM_SEND(19),{17, 0, 0x80,0x01,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x07,0x01,0x05,0x44,0x0C,0xCE,0xE7}},
        {LCM_SEND(6),{4, 0, 0x90,0x62,0x0E,0x00}},
//Blank 20
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x14}},
        {LCM_SEND(19),{17, 0, 0x80,0x91,0x01,0x80,0xA6,0xE8,0xEF,0xF7,0xFB,0xFD,0x7E,0x00,0x00,0x00,0x68,0xC5,0x47}},
        {LCM_SEND(19),{17, 0, 0x90,0x27,0x3D,0x20,0x36,0x3A,0xE9,0x01,0x71,0xD1,0x49,0x0F,0x88,0x89,0x4E,0x7A,0x80}},
        {LCM_SEND(19),{17, 0, 0xA0,0x39,0x74,0xD2,0x08,0xCC,0xA0,0x93,0x46,0x00,0x18,0x01,0x00,0x00,0x00,0x00,0x00}},
        {LCM_SEND(19),{17, 0, 0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0xAD,0xD1,0x2A,0x00,0x40,0xA1}},
        {LCM_SEND(19),{17, 0, 0xC0,0x50,0x78,0x07,0x9D,0xF4,0x80,0x73,0x00,0x6F,0xA0,0x93,0x1E,0x70,0x0E,0xE0,0x05}},
        {LCM_SEND(19),{17, 0, 0xD0,0x74,0xD2,0x03,0xCE,0x01,0xBC,0x82,0x4E,0x7A,0xC0,0x39,0x80,0x77,0xD1,0x49,0x0F}},
        {LCM_SEND(19),{17, 0, 0xE0,0x38,0x07,0xF0,0x26,0x3A,0xE9,0x01,0xE7,0x00,0xDE,0x43,0x27,0x3D,0xE0,0x1C,0xC0}},
        {LCM_SEND(19),{17, 0, 0xF0,0x5B,0xE8,0xA4,0x07,0x9C,0x03,0x00,0x01,0xBF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00}},
//Blank 21
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x15}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
        {LCM_SEND(19),{17, 0, 0x90,0x00,0x00,0xD1,0x4A,0xC4,0xA8,0xD5,0x86,0xD0,0x6A,0x17,0x31,0x6A,0xB5,0x21,0xB4}},
        {LCM_SEND(19),{17, 0, 0xA0,0x5A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
        {LCM_SEND(19),{17, 0, 0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x00,0xF0,0x00,0x94,0x96,0xE3,0x04}},
        {LCM_SEND(19),{17, 0, 0xC0,0x43,0x71,0x38,0x55,0x95,0xAC,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0x39,0x95}},
        {LCM_SEND(19),{17, 0, 0xD0,0x41,0x08,0x80,0x53,0x39,0x0A,0x6A,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0x96,0xE3}},
        {LCM_SEND(19),{17, 0, 0xE0,0x00,0x02,0x61,0x38,0x55,0x85,0xA8,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0x39}},
        {LCM_SEND(19),{17, 0, 0xF0,0xD5,0x51,0x0C,0x81,0x53,0x39,0x4B,0x6A,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0x5B,0x02}},
//Blank 22
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x16}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
        {LCM_SEND(9),{7, 0, 0x90,0x00,0x00,0x00,0x00,0xD0,0x40}},
//Blank 24
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x18}},
        {LCM_SEND(19),{17, 0, 0x80,0xEF,0xBD,0xF7,0xDE,0x7B,0xEF,0xBD,0x07,0x08,0x08,0x0A,0x0C,0x0C,0x0C,0x0C,0x0C}},
        {LCM_SEND(19),{17, 0, 0x90,0x0C,0x0C,0x0C,0x5C,0x09,0xA8,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x5A}},
        {LCM_SEND(19),{17, 0, 0xA0,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x09,0x04,0xFF,0x05,0x80}},
        {LCM_SEND(18),{16, 0, 0xB0,0x80,0x00,0x04,0x20,0x00,0x01,0x08,0x40,0x00,0x02,0x10,0x80,0x00,0x04,0x0F}},
//Blank 25
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x19}},
        {LCM_SEND(19),{17, 0, 0x80,0xF0,0xD9,0xC8,0xBA,0xAF,0xA6,0x9E,0x98,0x92,0x8D,0x88,0x84,0x00,0xF0,0x6F,0xF6}},
        {LCM_SEND(19),{17, 0, 0x90,0xCF,0xFC,0x6F,0xF6,0xFE,0xFC,0x0A,0xFF,0xAF,0xB5,0x71,0x0E,0x6C,0x4A,0x69,0x08}},
        {LCM_SEND(10),{8, 0, 0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
//Blank 26
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x1A}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38,0x00,0x40}},
        {LCM_SEND(19),{17, 0, 0x90,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00,0xA0,0xA8}},
        {LCM_SEND(19),{17, 0, 0xA0,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC,0xFE,0xFF}},
        {LCM_SEND(19),{17, 0, 0xB0,0x00,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38,0x00}},
        {LCM_SEND(19),{17, 0, 0xC0,0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00,0xA0}},
        {LCM_SEND(19),{17, 0, 0xD0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC,0xFE}},
        {LCM_SEND(19),{17, 0, 0xE0,0xFF,0x00,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38}},
        {LCM_SEND(19),{17, 0, 0xF0,0x00,0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00}},
//Blank 27
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x1B}},
        {LCM_SEND(19),{17, 0, 0x80,0xA0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC}},
        {LCM_SEND(7),{5, 0, 0x90,0xFE,0xFF,0x00,0x00}},
//Blank 32
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x20}},
        {LCM_SEND(10),{8, 0, 0x80,0x8B,0x00,0x00,0x00,0x00,0x00,0x00}},
//Blank 34
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x22}},
        {LCM_SEND(16),{14, 0, 0x80,0x2D,0xD3,0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x1F,0x00}},
//Blank 35
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x23}},
        {LCM_SEND(19),{17, 0, 0x80,0x01,0x05,0x00,0x05,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}},
        {LCM_SEND(12),{10, 0, 0x90,0xFF,0x0F,0x00,0x00,0x24,0x00,0x00,0x00,0x00}},
//Blank 36
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x24}},
        {LCM_SEND(19),{17, 0, 0x80,0x00,0x03,0x00,0x9D,0xBF,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8B,0x20}},
//SPI not FINISH
        //GEN_WR(0x90,0x5A);
        {LCM_SEND(2),{0x90,0x5A}},
//SPI FINISH
        {LCM_SEND(2),{0x90,0xA5}},
//Blank select 2F
        {LCM_SEND(5),{3, 0, 0x50,0x5A,0x2F}},
        {LCM_SEND(2),{0x09,0x01}},

	{LCM_SEND(2), {0x11, 0x00}},
	{LCM_SLEEP(120)},
	{LCM_SEND(2), {0x29, 0x00}},
	{LCM_SLEEP(10)},
#endif
};


static LCM_Force_Cmd_Code rd_prep_code[]={
        {0x37, {LCM_SEND(2), {0x3, 0}}},
};

static LCM_Init_Code disp_on =  {LCM_SEND(1), {0x29}};

static LCM_Init_Code sleep_in =  {LCM_SEND(1), {0x10}};

static LCM_Init_Code sleep_out =  {LCM_SEND(1), {0x11}};

static int32_t ft8006m_mipi_init(struct panel_spec *self)
{
	int32_t i;
	LCM_Init_Code *init = init_data;
	unsigned int tag;

	mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
	mipi_gen_write_t mipi_gen_write = self->info.mipi->ops->mipi_gen_write;

	LCD_PRINT("ft8006m_init\n");

	mipi_set_cmd_mode();

	for(i = 0; i < ARRAY_SIZE(init_data); i++){
		tag = (init->tag >>24);
		if(tag & LCM_TAG_SEND){
			mipi_gen_write(init->data, (init->tag & LCM_TAG_MASK));
			udelay(20);
		}else if(tag & LCM_TAG_SLEEP){
			mdelay((init->tag & LCM_TAG_MASK));
		}
		init++;
	}
	return 0;
}

static uint32_t ft8006m_readid(struct panel_spec *self)
{
        /*Jessica TODO: need read id*/
        int32_t i = 0;
        uint32_t j =0;
        LCM_Force_Cmd_Code * rd_prepare = rd_prep_code;
        uint8_t read_data[4] = {0};
        int32_t read_rtn = 0;
        unsigned int tag = 0;
        mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
        mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;
        mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;
        mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;


        LCD_PRINT("lcd_ft8006m_mipi read id!\n");

        mipi_set_cmd_mode();
        for(j = 0; j < 4; j++){
                rd_prepare = rd_prep_code;
                for(i = 0; i < ARRAY_SIZE(rd_prep_code); i++){
                        tag = (rd_prepare->real_cmd_code.tag >> 24);
                        if(tag & LCM_TAG_SEND){
                                mipi_force_write(rd_prepare->datatype, rd_prepare->real_cmd_code.data, (rd_prepare->real_cmd_code.tag & LCM_TAG_MASK));
                        }else if(tag & LCM_TAG_SLEEP){
                                mdelay((rd_prepare->real_cmd_code.tag & LCM_TAG_MASK));
                        }
                        rd_prepare++;
                }
                mipi_eotp_set(0,0);
                read_rtn = mipi_force_read(0x50, 5,(uint8_t *)&read_data[0]);
                mipi_eotp_set(1,1);
                LCD_PRINT("lcd_ft8006m_mipi read id 0x50 value is 0x%x, 0x%x, 0x%x, 0x%x!\n", read_data[0], read_data[1], read_data[2], read_data[3]);

                if((0x2f == read_data[1])&&(0x70 == read_data[2])){
                        LCD_PRINT("lcd_ft8006_mipi read id success!\n");
			printf("I2C SCL :0x%x\n", readl(0x402a02AC));
			printf("I2c SDA :0x%x\n", readl(0x402a02B0));
			i2c_set_bus_num(0);
			i2c_init(100000, 0x3E);
			i2c_reg_write(0x3E, 0x00, 0x14);
			mdelay(50);
			i2c_reg_write(0x3E, 0x01, 0x14);
			mdelay(50);
                        return 0x8006;
                }
        }

        return 0;
}

int32_t ft8006m_reset(struct panel_spec *self)
{
	sprd_gpio_request(NULL, LCM_GPIO_RSTN);
	sprd_gpio_direction_output(NULL, LCM_GPIO_RSTN, 1);
	mdelay(5);
	sprd_gpio_direction_output(NULL, LCM_GPIO_RSTN, 0);
	mdelay(5);
	sprd_gpio_direction_output(NULL, LCM_GPIO_RSTN, 1);
	mdelay(20);

	return 0;
}

static struct panel_operations lcd_ft8006m_mipi_operations = {
	.panel_init = ft8006m_mipi_init,
	.panel_readid = ft8006m_readid,
	.panel_reset = ft8006m_reset,
};

static struct timing_rgb lcd_ft8006m_mipi_timing = {
	.hfp = 45,
	.hbp = 25,
	.hsync = 14,
	.vfp = 195,
	.vbp = 25,
	.vsync = 8,
};

static struct info_mipi lcd_ft8006m_mipi_info = {
	.work_mode  = SPRDFB_MIPI_MODE_VIDEO,
	.video_bus_width = 24, /*18,16*/
	.lan_number = 4,
	.phy_feq = 500*1000,
	.h_sync_pol = SPRDFB_POLARITY_POS,
	.v_sync_pol = SPRDFB_POLARITY_POS,
	.de_pol = SPRDFB_POLARITY_POS,
	.te_pol = SPRDFB_POLARITY_POS,
	.color_mode_pol = SPRDFB_POLARITY_NEG,
	.shut_down_pol = SPRDFB_POLARITY_NEG,
	.timing = &lcd_ft8006m_mipi_timing,
	.ops = NULL,
};

struct panel_spec lcd_ft8006m_mipi_spec = {
	.width = 720,
	.height = 1280,
	.fps = 60,
	.type = LCD_MODE_DSI,
	.direction = LCD_DIRECT_NORMAL,
	.is_need_reset = 1,
	.info = {
		.mipi = &lcd_ft8006m_mipi_info
	},
	.ops = &lcd_ft8006m_mipi_operations,
};
